{#
通用分页宏
用于统一所有页面的分页样式
#}

{% macro render_pagination(pagination, endpoint, aria_label='分页导航', keyword='', status_filter='', customer_filter='', date_from='', date_to='') %}
    {% if pagination.pages > 1 %}
        <div class="card-footer">
            <div class="d-flex justify-content-between align-items-center">
                <div class="text-muted">
                    <small>
                        显示第 {{ (pagination.page - 1) * pagination.per_page + 1 }} -
                        {{ pagination.page * pagination.per_page if pagination.page * pagination.per_page < pagination.total else pagination.total }} 条，
                        共 {{ pagination.total }} 条记录
                    </small>
                </div>
                <nav aria-label="{{ aria_label }}">
                    <ul class="pagination pagination-sm mb-0">
                        {% if pagination.has_prev %}
                            <li class="page-item">
                                <a class="page-link" href="{{ url_for(endpoint, page=pagination.prev_num, keyword=keyword, status_filter=status_filter, customer_filter=customer_filter, date_from=date_from, date_to=date_to) }}">
                                    <i class="bi bi-chevron-left"></i>
                                </a>
                            </li>
                        {% endif %}

                        {% for page_num in pagination.iter_pages() %}
                            {% if page_num %}
                                {% if page_num != pagination.page %}
                                    <li class="page-item">
                                        <a class="page-link" href="{{ url_for(endpoint, page=page_num, keyword=keyword, status_filter=status_filter, customer_filter=customer_filter, date_from=date_from, date_to=date_to) }}">
                                            {{ page_num }}
                                        </a>
                                    </li>
                                {% else %}
                                    <li class="page-item active">
                                        <span class="page-link">{{ page_num }}</span>
                                    </li>
                                {% endif %}
                            {% else %}
                                <li class="page-item disabled">
                                    <span class="page-link">…</span>
                                </li>
                            {% endif %}
                        {% endfor %}

                        {% if pagination.has_next %}
                            <li class="page-item">
                                <a class="page-link" href="{{ url_for(endpoint, page=pagination.next_num, keyword=keyword, status_filter=status_filter, customer_filter=customer_filter, date_from=date_from, date_to=date_to) }}">
                                    <i class="bi bi-chevron-right"></i>
                                </a>
                            </li>
                        {% endif %}
                    </ul>
                </nav>
            </div>
        </div>
    {% endif %}
{% endmacro %}
